package com.zb.config;

import cn.dev33.satoken.interceptor.SaInterceptor;
import cn.dev33.satoken.router.SaRouter;
import cn.dev33.satoken.stp.StpUtil;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author WEN
 * @Date 2023/7/11 0011
 **/
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new SaInterceptor(handler -> {
            SaRouter.match("/**")
                    .notMatch(ignorePath())
                    .check(r -> StpUtil.checkLogin());
        }));
    }

    /**
     * 配置无需拦截的路径
     * @return
     */
    private List<String> ignorePath() {
        List<String> path = new ArrayList<>();
        path.add("/account/registerAccount");
        path.add("/account/loginPageUpdatePassword");
        path.add("/adm/login");

        path.add("/doc.html");
        path.add("/webjars/**");
        path.add("/swagger-resources");
        path.add("/v2/api-docs");
        path.add("/favicon.ico");
        // 短信
        path.add("/sms/**");

        return path;
    }



}
